import React, { Component } from 'react';
import store from '../store'

class Redux1 extends Component {
  constructor() {
    super()
    this.state = {
      user:{},
      order:{}
    }
  }
  componentDidMount() {
    this.setState(store.getState());
    // // 开启订阅
    this.un = store.subscribe(()=>{
      this.setState(store.getState());
    })
  }
  componentWillUnmount() {
    this.un()
  }
  changeAge() {
    // store.dispatch(actionCreator.changeAge())
  }
  render() {
    return (
      <div>
        <p>store</p>
        <p>年龄：{this.state.user.age}</p>
        <button onClick={()=>this.changeAge()}>修改年龄</button>
      </div>
    );
  }
}

export default Redux1;
